package com.beeantec.jnrerc.modules.banner.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.beeantec.jnrerc.core.annon.LogInject;
import com.beeantec.jnrerc.core.api.ApiRest;
import com.beeantec.jnrerc.core.api.controller.BaseController;
import com.beeantec.jnrerc.core.api.dto.PagingReqDTO;
import com.beeantec.jnrerc.dto.request.BannerDelDTO;
import com.beeantec.jnrerc.entity.Banner;
import com.beeantec.jnrerc.entity.Course;
import com.beeantec.jnrerc.entity.News;
import com.beeantec.jnrerc.modules.banner.service.BannerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 课程分类
 *
 * @author Anthony
 */
@RestController
@RequestMapping(value = "/api/banner")
@Api(value = "轮播图", tags = "轮播图")
public class BannerController extends BaseController {
    @Autowired
    private BannerService bannerService;
    /**
     * 添加banner
     *
     * @param banner
     * @return
     */
    @ApiOperation(value = "添加Banner", notes = "添加Banner")
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public ApiRest<Boolean> add(@RequestBody Banner banner) {
        Boolean result =bannerService.save(banner);
        return success(result);
    }


    /**
     * 删除Banner
     *
     * @param bannerDelDTO
     * @return
     */
    @ApiOperation(value = "删除Banner", notes = "删除Banner")
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public ApiRest<Boolean> delete(@RequestBody BannerDelDTO bannerDelDTO) {
        Boolean result =bannerService.removeById(bannerDelDTO.getId());
        return success(result);
    }



    /**
     * 获取Banner列表
     * @return
     */
    @LogInject(title = "获取Banner列表")
    @CrossOrigin
    @ApiOperation(value = "获取Banner列表")
    @RequestMapping(value = "/list", method = {RequestMethod.POST})
    public ApiRest<List<Banner>> list(){
        return super.success(bannerService.list());
    }

}
